﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace CLEXA.DataContracts
{
    [DataContract]
    public class ColumnData
    {
        private static readonly IEqualityComparer<ColumnData> valueComparer = new ColumnDataValueComparer();
        [DataMember]
        private readonly string name;
        [DataMember]
        private readonly string dataType;

        public static IEqualityComparer<ColumnData> ValueComparer
        {
            get { return ColumnData.valueComparer; }
        } 

        public string Name
        {
            get { return name; }
        }

        public string DataType
        {
            get { return dataType; }
        }

        private ColumnData()
        {
        }

        public ColumnData(string name, string dataType)
        {
            this.name = name;
            this.dataType = dataType;
        }

        public override string ToString()
        {
            return string.Format("Name: {0}, DataType: {1}", Name, DataType);
        }

        private sealed class ColumnDataValueComparer : IEqualityComparer<ColumnData>
        {
            public bool Equals(ColumnData x, ColumnData y)
            {
                if (Object.ReferenceEquals(x, y))
                {
                    return true;
                }
                if (Object.ReferenceEquals(x, null))
                {
                    return false;
                }
                if (Object.ReferenceEquals(y, null))
                {
                    return false;
                }

                return x.name == y.name && x.dataType == y.dataType;
            }

            public int GetHashCode(ColumnData obj)
            {
                if (obj == null)
                {
                    return 0;
                }
                else
                {
                    return obj.name.GetHashCode() ^ obj.dataType.GetHashCode();
                }
            }
        }
    }
}
